﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;

/// <summary>
///ConnPool 的摘要说明
/// </summary>
public class ConnPool
{
    public static List<SqlConnection> Pools = new List<SqlConnection>();

	public ConnPool()
	{
		//
		//TODO: 在此处添加构造函数逻辑
		//
	}

    public static void init() 
    {
        for (int i = 0; i < 20; i++) 
        {
            Pools.Add(new SqlConnection(pay.DAL.DBConn.Con_UserAgent));
        }

        foreach (SqlConnection con in Pools) 
        {
            con.Open();
        }
    }

    public static SqlConnection GetConn() 
    {
        List<SqlConnection> tpool = Pools.Where(a => a.State != ConnectionState.Executing).ToList();
        if (tpool.Count > 0)
        {
            return tpool[0];
        }
        else 
        {
            //return new SqlConnection(pay.DAL.DBConn.Con_UserAgent);
            return null;
        }        
    }
}